﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    查询分析报告
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style> 
    .ui-datepicker-calendar { 
        display: none; 
    } 
    </style> 

    
    <%
        DateTime begin = (DateTime)ViewData["begin"];
        DateTime end = (DateTime)ViewData["end"];
        bool showResult = (bool)ViewData["showResults"];
        int stype = (int) ViewData["stype"];
    %>

    <div class="screen_area">
    <form method="post" onsubmit="return validateForm();" action="<%=Url.Content("~/Reporting/Query") %>">
        <div>
        <%if ((bool)ViewData["showFactory"])
            {%>
        <label class="lab" style="width:90px;">选择公司：</label><%= Html.DropDownList("factoryId", ViewData["factories"] as List<SelectListItem>, "请选择公司", new { onchange = "showStacks();" })%>
        <span style="margin-left:20px"></span>
        <%
            }
            else
            {
        %>
        <%=Html.Hidden("factoryId", ViewData["factoryId"]) %>
        <%=Html.Hidden("PageNo", ViewData["currentPage"]) %>
        <%
            }
        %>
        <label>请选择堆场/尾矿库：</label><span id="stackList"><%= Html.DropDownList("stackId", ViewData["stacksAndTailingponds"] as List<SelectListItem>, "请选择", new { onchange = "changeInnormalItems();" })%></span>
        </div>
        <div style="margin-top:10px">
            <label class="lab" style="width:90px;">时间区间：</label>
            <span>从 <input type="text" name="begin" id="begin" size="6" value="<%=begin.Year %>-<%=begin.Month %>" class="ipt_date" readonly="readonly" /></span>
            <span>到 <input type="text" name="end" id="end" size="6" value="<%=end.Year %>-<%=end.Month %>" class="ipt_date" readonly="readonly" /></span>
            <span style="padding-left:1.8em;"><input type="checkbox" name="inNormal" id="inNormal" value="1" onclick="showInnormalItems();" <%if ((int)ViewData["inNormal"] == 1){ %>checked="checked"<%} %> /><label for="inNormal">根据是否出现异常情况查询</label></span>
        </div>

        <div id="innormalItems" style="display:none;margin-left:50px">
            <div id="stackInNormalItems" style="display:none">
                <p class="chk_area">
                    <cite><input type="checkbox" name="stackWater" id="stackWater" value="1" <%if ((int)ViewData["stackWater"] == 1){ %>checked="checked"<%} %> /><label for="stackWater">水位及水质</label></cite>
                    <cite><input type="checkbox" name="stackBackWater" id="stackBackWater" value="1" <%if ((int)ViewData["stackBackWater"] == 1){ %>checked="checked"<%} %> /><label for="stackBackWater">进浆及回水</label></cite>
                    <cite><input type="checkbox" name="stackSettle" id="stackSettle" value="1" <%if ((int)ViewData["stackSettle"] == 1){ %>checked="checked"<%} %> /><label for="stackSettle">沉降及位移观测</label></cite>
                    <cite><input type="checkbox" name="stackArdealite" id="stackArdealite" value="1" <%if ((int)ViewData["stackArdealite"] == 1){ %>checked="checked"<%} %> /><label for="stackArdealite">磷石膏堆积坝</label></cite>
                </p>
                <p class="chk_area">
                    <cite><input type="checkbox" name="stackDitch" id="stackDitch" value="1" <%if ((int)ViewData["stackDitch"] == 1){ %>checked="checked"<%} %> /><label for="stackDitch">截洪沟</label></cite>
                    <cite><input type="checkbox" name="stackWell" id="stackWell" value="1" <%if ((int)ViewData["stackWell"] == 1){ %>checked="checked"<%} %> /><label for="stackWell">浸润线观测</label></cite>
                    <cite><input type="checkbox" name="stackBase" id="stackBase" value="1" <%if ((int)ViewData["stackBase"] == 1){ %>checked="checked"<%} %> /><label for="stackBase">渗压观测</label></cite>
                    <cite><input type="checkbox" name="stackDrain" id="stackDrain" value="1" <%if ((int)ViewData["stackDrain"] == 1){ %>checked="checked"<%} %> /><label for="stackDrain">导渗系统</label></cite>
                </p>
            </div>
            <div id="tailingpondInNormalItems" style="display:none">
                <p class="chk_area">
                    <cite><input type="checkbox" name="tailingpondWater" id="tailingpondWater" value="1" <%if ((int)ViewData["tailingpondWater"] == 1){ %>checked="checked"<%} %> /><label for="tailingpondWater">水位及水质</label></cite>
                    <cite><input type="checkbox" name="tailingpondBackWater" id="tailingpondBackWater" value="1" <%if ((int)ViewData["tailingpondBackWater"] == 1){ %>checked="checked"<%} %> /><label for="tailingpondBackWater">进浆及回水</label></cite>
                    <cite><input type="checkbox" name="tailingpondDitch" id="tailingpondDitch" value="1" <%if ((int)ViewData["tailingpondDitch"] == 1){ %>checked="checked"<%} %> /><label for="tailingpondDitch">沉降及位移</label></cite>
                    <cite><input type="checkbox" name="tailingpondFilldam" id="tailingpondFilldam" value="1" <%if ((int)ViewData["tailingpondFilldam"] == 1){ %>checked="checked"<%} %> /><label for="tailingpondFilldam">尾矿堆积坝</label></cite>
                </p>
            </div>
        </div>
        <div style="margin-top:10px;margin-left:30px">
              <input type="submit" value="查  询" />
        </div>
    </form>
    </div>

    <%if (showResult)
      {
          if (stype == 0)
          {
              IEnumerable<StackReporting> reportings = (IEnumerable<StackReporting>)ViewData["reportings"];
    %>
    
    
    <table cellpadding="4" cellspacing="0" class="com_from_table3">
        <tr>
            <th style="width:68px;">时间</th>
            <th>堆场名称</th>
            <th>水位及水质</th>
            <th>进浆及回水</th>
            <th>沉降及位移观测</th>
            <th>磷石膏堆积坝</th>
            <th>截洪沟</th>
            <th>浸润线观测</th>
            <th>渗压观测</th>
            <th>导渗系统</th>
            <th>&nbsp;</th>
        </tr>
        <%if (reportings != null)
          {
              foreach (StackReporting r in reportings) 
              {
        %>
        <tr style="text-align:center;">
            <td><%=r.date.Year + "-" + r.date.Month %></td>
            <td><%=r.StackName %></td>
            <td><%=r.water == null ? "-":(r.water == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.backwater == null ? "-":(r.backwater == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.settle == null ? "-":(r.settle == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.ardealite == null ? "-":(r.ardealite == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.ditch == null ? "-":(r.ditch == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.piezometerwell == null ? "-":(r.piezometerwell == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.piezometerbase == null ? "-":(r.piezometerbase == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.drain == null ? "-":(r.drain == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><a href="/Reporting/View/<%=r.id %>" target="_blank">查看报告详情</a></td>
        </tr>
        <%
              }
          }
        %>
    </table>
    <%         
          }
          else if (stype == 1)
          {
              IEnumerable<TailingpondReporting> reportings = (IEnumerable<TailingpondReporting>)ViewData["reportings"];
    %>
    <table cellpadding="4" cellspacing="0" class="com_from_table3">
        <tr>
            <td colspan="11"><strong class="space">监测项目</strong></td>
        </tr>
        <tr>
            <th style="width:68px;">时间</th>
            <th>尾矿库名称</th>
            <th>水位及水质</th>
            <th>进浆及回水</th>
            <th>沉降及位移</th>
            <th>尾矿堆积坝</th>
            <th>&nbsp;</th>
        </tr>
        <tr>
            
        </tr>
        <%if (reportings != null)
          {
              foreach (TailingpondReporting r in reportings) 
              {
        %>
        <tr style="text-align:center;">
            <td><%=r.date.Year + "-" + r.date.Month %></td>
            <td><%=r.TailingpondName %></td>
            <td><%=r.water == null ? "-":(r.water == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.backwater == null ? "-":(r.backwater == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.ditch == null ? "-":(r.ditch == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><%=r.filldam == null ? "-":(r.filldam == 1 ? "<font style='color:red;font-weight:bold'>异常</font>" : "正常")%></td>
            <td><a href="/Reporting/View/<%=r.id %>" target="_blank">查看报告详情</a></td>
        </tr>
        <%
              }
          }
        %>
    </table>
    <%
          }
    %>
    <%} %>

    <% Html.RenderPartial("Pagination", ViewData); %>
    <script language="javascript" type="text/javascript">
        $('#begin').datepicker({ 
                changeMonth: true,
                changeYear: true,
                showButtonPanel: false,
                dateFormat: 'yy-MM',
                onClose: function(dateText, inst) { 
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
         });
        $('#end').datepicker({
                changeMonth: true,
                changeYear: true,
                showButtonPanel: false,
                dateFormat: 'yy-MM',
                onClose: function(dateText, inst) { 
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
        });

        function showStacks() {
            var factoryId = document.getElementById("factoryId").value;
            if (factoryId == "" || factoryId == 0) return;
            $.ajax({ 
                    type: "POST",
                    url: "<%=Url.Content("~/Modification/ListStacks") %>",
                    data: "factoryId=" + factoryId,
                    success: function (data) { $("#stackList").html(data);$("#stackId").on("change", function(){changeInnormalItems();});}
            });
        }

        function showInnormalItems() {
            if ($("#inNormal").prop("checked") == true)
            {
                $("#innormalItems").css("display", "");
            } else {
                $("#innormalItems").css("display", "none");
            }
        }

        function changeInnormalItems() {
            var value = $("#stackId option:selected").first().val();

            $("#stackInNormalItems").css("display", "none");
            $("#tailingpondInNormalItems").css("display", "none");
            var stackReg = /^0-/;
            var tailingpondReg = /^1-/;

            if (stackReg.test(value)) {
                $("#stackInNormalItems").css("display", "");
            }

            if (tailingpondReg.test(value)) {
                $("#tailingpondInNormalItems").css("display", "");
            }
        }

        function validateForm()
        {
            var factoryId = $("#factoryId").val();
            var stackId = $("#stackId").val();
            var begin = $("#begin").val();
            var end = $("#end").val();

            if (factoryId == null || factoryId == "" || factoryId == undefined)
            {
                alert("请选择公司");
                $("#factoryId").focus();
                return false;
            }

            if (stackId == null || stackId == "" || stackId == undefined)
            {
                alert("请选择堆场\尾矿库");
                $("#stackId").focus();
                return false;
            }

            if (begin == null || begin == "" || begin == undefined)
            {
                alert("请选择查询起始时间");
                $("#begin").focus();
                return false;
            }

            if (end == null || end == "" || end == undefined)
            {
                alert("请选择查询结束时间");
                $("#end").focus();
                return false;
            }

            return true;
        }

        $(document).ready(function () {
            changeInnormalItems();
            showInnormalItems();
        });
    </script>
</asp:Content>
